#!/bin/sh

info="$(curl -s ipinfo.io/loc)"
location="$HOME/.local/state/location"
latitude="$(awk -F "," '{ printf "%.1f", $1 }' "$location")"
longitude="$(awk -F "," '{ printf "%.1f", $2 }' "$location")"

pkill wlsunset || wlsunset -l "$latitude" -L "$longitude" &

if [ -n "$info" ]; then
    printf "%s" "$info" > "$location"
fi
